// 
// Decompiled by Procyon v0.5.30
// 

package org.bp.util;

import java.util.Collections;
import java.util.HashMap;
import java.util.Enumeration;
import java.io.UnsupportedEncodingException;
import java.util.ResourceBundle;
import java.util.Map;

public class PropertyUtil
{
    private static Map<String, PropertyUtil> instance;
    protected String sourceUrl;
    protected ResourceBundle resourceBundle;
    private static Map<String, String> convert;
    
    protected PropertyUtil(final String sourceUrl) {
        this.sourceUrl = sourceUrl;
        this.load();
    }
    
    public static PropertyUtil getInstance(final String sourceUrl) {
        synchronized (PropertyUtil.class) {
            PropertyUtil manager = PropertyUtil.instance.get(sourceUrl);
            if (manager == null) {
                manager = new PropertyUtil(sourceUrl);
                PropertyUtil.instance.put(sourceUrl, manager);
            }
            return manager;
        }
    }
    
    private synchronized void load() {
        try {
            this.resourceBundle = ResourceBundle.getBundle(this.sourceUrl);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("sourceUrl = " + this.sourceUrl + "file load error!", e);
        }
    }
    
    public String getProperty(final String key) {
        try {
            return new String(this.resourceBundle.getString(key).getBytes("iso-8859-1"), "utf-8");
        }
        catch (UnsupportedEncodingException ex) {
            return this.resourceBundle.getString(key);
        }
    }
    
    public Map<String, String> readyConvert() {
        final Enumeration<String> enu = this.resourceBundle.getKeys();
        while (enu.hasMoreElements()) {
            final String key = enu.nextElement();
            final String value = this.resourceBundle.getString(key);
            PropertyUtil.convert.put(value, key);
        }
        return PropertyUtil.convert;
    }
    
    public Map<String, String> readyConvert(final ResourceBundle resourcebundle) {
        final Enumeration<String> enu = resourcebundle.getKeys();
        while (enu.hasMoreElements()) {
            final String key = enu.nextElement();
            final String value = resourcebundle.getString(key);
            PropertyUtil.convert.put(value, key);
        }
        return PropertyUtil.convert;
    }
    
    static {
        PropertyUtil.instance = Collections.synchronizedMap(new HashMap<String, PropertyUtil>());
        PropertyUtil.convert = Collections.synchronizedMap(new HashMap<String, String>());
    }
}
